home *** CD-ROM | disk | FTP | other *** search
- Path: news2.ios.com!usenet
- From: vlad@gramercy.ios.com (Vlastimil Adamovsky)
- Newsgroups: comp.lang.c++
- Subject: Re: Visual C++ 4.0 lacking initializers?
- Date: Fri, 26 Jan 1996 14:05:56 GMT
- Organization: Internet Online Services
- Message-ID: <4eamnb$q16@news2.ios.com>
- References: <31049C46.A26@oz.is>
- NNTP-Posting-Host: ppp-37.ts-7.hck.idt.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- Hßlfdan Ingvarsson <halfdan@oz.is> wrote:
-
- >Is it me or is this sort of code not possible with VC++ 4.0?
-
- >// Declarations of class Foo
-
- >// VC++ Complains about the line below with the error
- >// error C2436: '__ctor' : cannot initialize member functions
- >Foo::Foo(void) : Foo::Foo(10) {}
-
- >Foo::Foo(x)
- >{
- > // Some stuff
- >}
-
- I think, that a constructor can call constructors of immediate
- superclasses or initializers of member data. That's why compiler
- thinks that Foo::Foo(10) is some initializer. Anyway it it would be
- legal, you should write
-
- Foo::Foo
- : Foo(10)
- {}
-
- But but from clearness point of view it is better to write:
-
- Foo::Foo()
- : x(1)
- {}
-
- if you have no value to initialize, then write:
-
- Foo::initialize(int i)
- {
- .... do something with i
- }
-
- Foo::Foo()
- {
- initialize(10);
- }
- *******************************************
- * Vlastimil Adamovsky *
- * Smalltalk, C++ and Envelop development *
- *******************************************
-
-